#!/usr/bin/env python

import unittest
from vm import VM

class TestVM(VM, unittest.TestCase):
  def __init__(self, *args, **kwargs):
    unittest.TestCase.__init__(self, *args, **kwargs)
    VM.__init__(self)

  def setUp(self):
    #print "setUp"
    pass

  def tearDown(self):
    #print "tearDown"
    pass

  def test_deployVirtualMachine(self):
    serviceofferingid = 1;
    templateid = 2;
    zoneid = 1;
    response = self.deployVirtualMachine(serviceofferingid, templateid, zoneid)
    self.assertEqual(response['serviceofferingid'], serviceofferingid)
    self.assertEqual(response['templateid'], templateid)
    self.assertEqual(response['zoneid'], zoneid)

  def test_listVirtualMachines(self):
    response = self.listVirtualMachines()
    self.assertTrue(len(response) == 0 or response['count'] > 0)
    
  def test_startVirtualMachine(self):
    machineid = 3
    response = self.startVirtualMachine(machineid)
    self.assertEqual(response["id"], machineid)
    self.assertEqual(response["state"], "Running")

  def test_stopVirtualMachine(self):
    machineid = 3
    response = self.stopVirtualMachine(machineid)
    self.assertEqual(response["id"], machineid)
    self.assertEqual(response["state"], "Stopped")

  def test_rebootVirtualMachine(self):
    machineid = 3
    response = self.rebootVirtualMachine(machineid)
    self.assertEqual(response["id"], machineid)
    self.assertEqual(response["state"], "Running")

  def test_destroyVirtualMachine(self):
    machineid = 5
    response = self.destroyVirtualMachine(machineid)
    self.assertEqual(response["id"], machineid)
    self.assertEqual(response["state"], "Destroyed")

  def test_resetPasswordForVirtualMachine(self):
    machineid = 10
    response = self.resetPasswordForVirtualMachine(machineid)
    self.assertEqual(response["id"], machineid)

  def test_migrateVirtualMachine(self):
    machineid = 10
    hostid = 1
    response = self.migrateVirtualMachine(machineid, hostid)
    self.assertEqual(response["id"], machineid)
    self.assertEqual(response["hostid"], hostid)

def get_suite():
  suite = unittest.TestSuite()
  #suite.addTest(TestVM("test_deployVirtualMachine"))
  #suite.addTest(TestVM("test_listVirtualMachines"))
  #suite.addTest(TestVM("test_startVirtualMachine"))
  #suite.addTest(TestVM("test_stopVirtualMachine"))
  #suite.addTest(TestVM("test_rebootVirtualMachine"))
  #suite.addTest(TestVM("test_destroyVirtualMachine"))
  #suite.addTest(TestVM("test_resetPasswordForVirtualMachine"))
  #suite.addTest(TestVM("test_migrateVirtualMachine"))
  return suite

if __name__ == "__main__":
  suite = get_suite()
  runner = unittest.TextTestRunner()
  runner.run(suite)
